package Jobs;

import java.util.Date;
import java.util.List;

import common.FBUtil;
import common.TVRageRequest;

import models.Episode;
import models.Serie;
import models.User;
import play.jobs.*;

@Every("24h")
public class EpisodeNotifications extends Job {
    
    public void doJob() {
        
		List<Episode> todayEpisodes = Episode.upcomingEpisodes(new Date());
		
		List<User> users = User.findAll();
		
		for (User u : users) {
			for (Serie s : u.getFollows()) {
				for (Episode e : todayEpisodes) {
					if (e.getSerie().getId().equals(s.getId())) {
						FBUtil.getInstance().sentEpisodeNotification(e);
					}
				}
			}
		}
    }
    
}
